package com.example.magictowerx;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.view.KeyEvent;

public class MySet
{
    public static final int	GAME_SPLASH		= 1;
    public static final int	GAME_MENU		= 2;
    public static final int	GAME_ABOUT		= 3;
    public static final int	GAME_HELP		= 4;
    public static final int	GAME_RUN		= 5;
    public static final int	GAME_CONTINUE	= 6;
    public static final int	KEY_DPAD_UP		= KeyEvent.KEYCODE_DPAD_UP;
    public static final int	KEY_DPAD_DOWN	= KeyEvent.KEYCODE_DPAD_DOWN;
    public static final int	KEY_DPAD_LEFT	= KeyEvent.KEYCODE_DPAD_LEFT;
    public static final int	KEY_DPAD_RIGHT	= KeyEvent.KEYCODE_DPAD_RIGHT;
    public static final int	KEY_DPAD_OK		= KeyEvent.KEYCODE_BACK;	// 23
    /* 右软键需要自己定义，否则右软键则是退出 */
    public static final int	KEY_SOFT_RIGHT	= KeyEvent.KEYCODE_DPAD_CENTER;			// 4

    /* 游戏循环时间 */
    public static final int	GAME_LOOP		= 100;
    /* 屏幕的宽高 */
    public static final int	SCREENW			= 1080; //屏幕宽
    public static final int	SCREENH			= 1920; //屏幕高
    public static final int	BORDERW			= 1056; //沙盒宽
    public static final int	BORDERH			= 1152; //沙盒高
    public static final int	BORDERX			= (MySet.SCREENW - BORDERW) / 2; //沙盒横坐标（相对左上角）
    public static final int	BORDERY			= 60; //沙盒纵坐标（相对左上角）
    public static final int	MessageBoxH		= 210;

    /* 文字的尺寸 */
    public static final int	TextSize		= 48;


    public static boolean touchUp (int x ,int y)
    {
        return x>=300 && x<= 440 && y>=1350 && y<= 1490;
    }

    public static boolean touchDown (int x ,int y)
    {
        return x>=300 && x<= 440 && y>=1630 && y<= 1770;
    }

    public static boolean touchRight (int x ,int y)
    {
        return x>=440 && x<= 580 && y>=1490 && y<= 1630;
    }

    public static boolean touchLeft (int x ,int y)
    {
        return x>=160 && x<= 300 && y>=1490 && y<= 1630;
    }

    public static boolean touchOK (int x ,int y)
    {
        return x>=600 && x<= 840 && y>=1380 && y<= 1620;
    }

    public static boolean touchBack (int x ,int y)
    {
        return x>=800 && x<= 1040 && y>=1520 && y<= 1760;
    }

    public static boolean touchYes (int x ,int y)
    {
        return x>=350 && x<=400 && y>=(MySet.SCREENH - MySet.TextSize) / 2 && y<=((MySet.SCREENH - MySet.TextSize) / 2) + MySet.TextSize ;
    }

    public static boolean touchNo (int x ,int y)
    {
        return x>=MySet.SCREENW - 400 && x<=MySet.SCREENW - 350 && y>=(MySet.SCREENH - MySet.TextSize) / 2 && y<=((MySet.SCREENH - MySet.TextSize) / 2) + MySet.TextSize ;
    }

    public static void fillRect(Canvas canvas, Rect rect, Paint paint)
    {
        paint.setStyle(Paint.Style.FILL);
        canvas.drawRect(rect.left, rect.top, rect.right, rect.bottom, paint);
    }


    public static void drawRect(Canvas canvas, Rect rect, Paint paint)
    {
        paint.setStyle(Paint.Style.STROKE);
        canvas.drawRect(rect.left, rect.top, rect.right, rect.bottom, paint);
    }


    public static void SETAEERECT(Rect rect, int x, int y, int w, int h)
    {
        rect.left = x;
        rect.top = y;
        rect.right = x + w;
        rect.bottom = y + h;
    }


    public static void fillRect(Canvas canvas, int x, int y, int w, int h, Paint paint) //绘制填充矩形
    {
        paint.setStyle(Paint.Style.FILL);
        canvas.drawRect(x, y, x + w, y + h, paint);
    }


    public static void drawRect(Canvas canvas, int x, int y, int w, int h, Paint paint) //绘制矩形框
    {
        paint.setStyle(Paint.Style.STROKE);
        canvas.drawRect(x, y, x + w, y + h, paint);
    }


    /*------------------------------------
     * 绘制图片
     *
     * @param		x 屏幕上的x坐标
     * @param		y 屏幕上的y坐标
     * @param		w 要绘制的图片的宽度
     * @param		h 要绘制的图片的高度
     * @param		bx图片上的x坐标
     * @param		by图片上的y坐标
     *
     * @return		null
     ------------------------------------*/
    public static void drawImage(Canvas canvas, Bitmap blt, int x, int y, int w, int h, int bx, int by)
    {
        Rect src = new Rect();// 图片
        Rect dst = new Rect();// 屏幕
        src.left = bx;
        src.top = by;
        src.right = bx + w;
        src.bottom = by + h;
        dst.left = x;
        dst.top = y;
        dst.right = x + w;
        dst.bottom = y + h;
        canvas.drawBitmap(blt, src, dst, null);

        src = null;
        dst = null;
    }


    public static void drawImage(Canvas canvas, Bitmap bitmap, float x, float y)
    {
        canvas.drawBitmap(bitmap, x, y, null);
    }


    public static void drawString(Canvas canvas, String str, float x, float y, Paint paint)
    {
        canvas.drawText(str, x, y + paint.getTextSize(), paint);
    }
}

